home *** CD-ROM | disk | FTP | other *** search
- Path: web.cae.ca!usenet
- From: fraserh@cae.ca (Fraser Hutchinson)
- Newsgroups: comp.lang.c++
- Subject: Re: unsigned char question
- Date: 4 Mar 1996 18:21:36 GMT
- Organization: CAE Electronics Ltd.
- Message-ID: <4hfcbg$t53@web.cae.ca>
- References: <3136864B.7154@eds.com>
- NNTP-Posting-Host: pch63.cae.ca
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <3136864B.7154@eds.com>, lnusmsc.phoeks01@eds.com says...
- >
- >This is a basic question but one I cannot answer. I am using VC++ 2.0
- >and I wish to assign a string to a variable of type UCHAR * (which is an
- unsigned char
- >within ODBC). The code is as follows
- >
- >UCHAR * server;
- >
- >server = "jmbademo";
-
- Two problems here - do you not have to allocate memory for the assignment
- statement? (Maybe I am missing something here)...
-
- For example, this should work:
-
- UCHAR *server = (UCHAR *)"jmbademo"; // static declaration
-
- Alternatively, I believe you must do this:
-
- UCHAR *server; // dynamic allocation
-
- server = new UCHAR[strlen(jmbademo")+1];
- strcpy(server, (UCHAR *)"jmbdemo");
-
-
-
- >When I attempt to compile this piece of code, I receive the following error:
- >
- >C:\cgi\Envvars\Envvar.cpp(417) : error C2446: '=' : no conversion from
- 'char[9]' to
- >'unsigned char*'
-
- This is the second problem.
-
- To the compiler, char * and unsigned char * are two different typws, you have
- to cast them as I did above.
-
- Regards,
-
- Fraser
-
-